{include file="common/head"}
<style>
    a {
        text-decoration: none;
    }

    input {
        display: initial !important;
    }
</style>
<link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
<script src="/static/flatpickr/flatpickr.min.js"></script>
</head>

<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col">
                <form action="/index.php/order/index" method="post">
                    <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
                        <input type="hidden" name="status" value="{$status}" />
                        <div class="col-1">
                            <h3>订单管理</h3>
                        </div>
                        <div class="col">
                            

                            <label for="customer">客户：</label>
                            <select name="customer" class="form-control" style="width:140px;display:initial;">
                                <option value="">所有</option>
                                {foreach $customer_list as $k=>$v}
                                <option value="{$v['id']}" {if $v['id']==$customer} selected{/if}>{$v['name']}</option>
                                {/foreach}
                            </select>
                            <label for="customer">状态：</label>
                            <select name="status" class="form-control" style="width:100px;display:initial;">
                                <option value="">所有</option>
                                {foreach $status_list as $k=>$v}
                                <option value="{$k}" {if $k==$status}selected{/if}>{$v[0]}</option>
                                {/foreach}
                            </select>

                            <label for="sdate">日期：</label>
                            <input class="form-control" type="text" value="{$sdate}" id="sdate" name="sdate"
                                placeholder="开始日期" />

                            <label for="sdate"></label>
                            <input class="form-control" type="text" value="{$edate}" id="edate" name="edate"
                                placeholder="结束日期" />

                            <label for="po">客户PO#</label>
                            <input class="form-control" type="text" value="{$po}" id="po" name="po"
                                placeholder="客户订单号" />
                            </label>
                            <label for="goods_name">产品</label>
                            <input class="form-control" type="text" value="{$goods_name}" id="goods_name" name="goods_name"
                                placeholder="品名" />
                            </label>

                            <button type="button" class="btn btn-warning query">
                                <span class="bi-search"></span>
                            </button>
                        </div>

                    </div>
                </form>
            </div>
        </div>

        <table class="table table-sm table-hover table-striped table-bordered" style="width: initial!important;">
            <thead class="table-info">
                <th>序号 SN</th>
                <th>客户订单号 PO#</th>
                <th>订单金额</th>
                <th>订单总数Qty</th>
                <th>交货总数</th>
                <th>未交总数</th>
                <th>客户</th>
                <th>下单人</th>
                <th>负责人</th>
                <th>下单时间</th>
                <th>交货日期</th>
                <th>剩余交货时间</th>
                <th>交货仓库 In stock#</th>
                <th>备注 Memo</th>
                <th>订单状态</th>

                <th>

                </th>
            </thead>
            <tbody>
                {foreach $list['data'] as $k=>$kv}
                <tr>
                    <td>{$k+1}</td>
                    <td>{$kv['order_no']}</td>
                    <td class="text-center">{$currency_symbol}{$kv['amount']}</td>
                    <td class="text-center">{$kv['qty']}</td>
                    <td class="text-center" style="color:{if $kv.status==3}#f60;{elseif $kv.status==4}blue;{/if}">
                        {$kv['delivered_qty']}</td>
                    <td class="text-center">{$kv['undelivered_qty']}</td>
                    <td>{$kv['customer_id_name']}</td>
                    <td>{$kv['contact']}</td>
                    <td>{$kv['sales_name']}</td>
                    <td>{$kv['create_time']}</td>
                    <td>{$kv['delivery_date']}</td>
                    <td>{$kv['days_left']}</td>
                    <td>{$kv['in_stock']}</td>
                    <td>{$kv['memo']}</td>
                    <td style="color:{if $kv.status==3}#f60;{elseif $kv.status==4}blue;{/if}">{$kv['status_name'][0]}</td>


                    <td class="text-nowrap">
                        <button type="button" class="btn btn-sm btn-info list" oid="{$kv['id']}">
                            <span class="bi-list"></span>
                        </button>
                        <button type="button" class="btn btn-sm btn-success log" oid="{$kv['id']}">
                            <span class="bi-book"></span>
                        </button>
                        {if $kv['status']==1}
                        <button tyle="button" class="btn btn-sm btn-success" oid="{$kv['id']}">
                            <span class="bi-check"></span>
                        </button>

                        <button tyle="button" class="btn btn-sm btn-danger btn_cancel" oid="{$kv['id']}">
                            <span class="bi-trash"></span>
                        </button>
                        {/if}



                    </td>
                </tr>
                {/foreach}

            </tbody>
        </table>
        {include file="common/pagination"}
    </div>

</body>

<script type="text/javascript">
    flatpickr("#sdate,#edate", {});

    $(document).ready(function () {
        setTimeout(function () { $(".query").show() }, 3000);

        $(".list").on('click', function () {
            var oid = $(this).attr('oid');
            layer.open({
                type: 2,
                title: '订单明细',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['900px', '600px'],
                content: '/index.php/order/order_list/id/' + oid
            });
        })

        $(".log").on('click', function () {
            var oid = $(this).attr('oid');
            layer.open({
                type: 2,
                title: '订单记录',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['700px', '500px'],
                content: '/index.php/order/order_log/id/' + oid
            });
        })

        $(".bi-check").on('click', function () {
            var oid = $(this).parent().attr('oid');
            layer.confirm('请在确认之前，仔细检查订单产品规格及数量！！！？', {
                btn: ['已经确认好了', '再检查一下'] //按钮
            }, function () {

                $.post("/order/order_check", {table:'order', id: oid, status: 2 }, function (res) {
                    if (res.code) {
                        //layer.open({content:'订单已确认!'});
                        location.reload();
                    } else {
                        layer.open({ content: '失败!' });
                    }
                });

            }, function () {
                layer.msg('取消操作!');
            });
        })

        $(".send").on('click', function () {
            var package_no = prompt("请输入快递单号或者输入【自行配送】");
            if (!package_no) {
                layer.msg('请输入快递单号或者输入【自行配送】!');
                return;
            }

            layer.msg(package_no);
            var oid = $(this).attr('oid');
            layer.confirm('是否确认发货？', {
                btn: ['确认', '不'] //按钮
            }, function () {
                $.post("/index.php/order/order_takex/id/" + oid, { id: oid, status: 3, package_no: package_no }, function (res) {
                    layer.msg(res.msg);
                });

            }, function () {
                layer.msg('操作取消!');
            });
        })



        $(".btn_cancel").on('click', function () {
            var oid = $(this).attr('oid');
            layer.confirm('确认把订单丢进垃圾筒吗？', {
                btn: ['Yes', 'No'] //按钮
            }, function () {

                $.post("/index.php/order/order_cancel", { table: 'order', id: oid }, function (res) {
                    console.log(res.msg)
                    if (res.code) {
                        location.reload();
                    } else {
                        layer.open({ 'content': res.msg });
                    }

                });

            }, function () {
                layer.msg('取消操作!');
            });

        })


        $(".query").on('click', function () {
            var cid = $("#customer_id").val();
            var order_no = $("#order_no").val();
            var sdate = $("#sdate").val();
            var edate = $("#edate").val();
            $("form").submit();
        })


    })



</script>

</body>

</html>